<!DOCTYPE html>
<html>
  <head>
    <title>换电站登录</title>
 
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
   <link href="<@spring.url '/static/css/login.css'></@spring.url>" rel="stylesheet" type="text/css"/>
   
<#include "bases/global_style.ftl">
<#include "bases/global_js.ftl">
   
  </head>
  
  <body class="indexBody">
  	<div class="indexBox">
  		<form class="indexForm loginForm" id="loginForm" action="<@spring.url '/do_login'></@spring.url>" method="post">
  			<div class="index-title">伯坦换电站计费平台登录</div>
			<div class="list-box">
				<div class="list-tr">
				 <#if user_name??>
					<input type="text" name="user_name" id="user_name" placeholder="用户名/手机号" value="${user_name}"/>
				 <#else>
				    <input type="text" name="user_name" id="user_name" placeholder="用户名/手机号"/>
				  </#if>
				</div>
				<div class="list-tr">
					<input type="password" name="passwords" id="passwords" placeholder="密码" />
				</div>
			</div>
			<div class="handle-bar">
				<div class="rememberPass"><input name="loginCheckbox1" id="loginCheckbox1" type="checkbox" value="" checked="checked"> 记住我</div>
			</div>
			
			<div class="foot-box btn1" id="loginSure">
				<a class="foot-butten a-white" href="javascript:;">登录</a>
			</div>
			
			<div class="error-resgister">
			    <#if alreadyLogin??><span id="errorContent">您的账号已在别处登录!</span></#if>
                <#if wrongpw??>><span id="errorContent">输入的账号或密码错误，请重新输入账号和密码!</span></#if>
			</div>
			
  		</form>
  		
  		<div id="copyrightPageBox"></div>
  	</div>
  	

     <div id="login-forgot" class="content-box bg-default hide">
           <div class="content-box-wrapper pad20A">

               <div class="form-group">
                   <div class="input-group">
                       <span class="input-group-addon addon-inside bg-gray">
                           <i class="glyph-icon icon-user"></i>
                       </span>
                       <input class="form-control" id="pw_retrieve_user" placeholder="请输入要找回密码的账号">
                   </div>
               </div>
           </div>
           <div class="button-pane text-center">
               <button type="button" class="btn btn-md btn-primary" onclick="pwRetrieve()">通过邮箱找回</button>
               <a href="#" class="btn btn-md btn-link switch-button" switch-target="#login-form" switch-parent="#login-forgot" title="Cancel">返回登陆</a>
           </div>
       </div>
 
 
       <div id="waiting" class="alert alert-info hide" role="alert">
           服务器正在处理您的请求，请稍候...
       </div>
       
  	<script type="text/javascript">
		$(document).ready(function(){
				loginSure();
			});
			
		function loginSure(){
			$("#loginSure").click(function(){
				var user_name=$("#user_name").val();
				var passwords=$("#passwords").val();
				
				if(user_name=="" || passwords==""){
					$(".error-resgister").css("display","block");
					$("#errorContent").text("您所填信息不完整！");
				}
				else{
					$("#errorContent").text("");
					$("#loginSure a").text("登录中...");
					$("#loginForm").submit();
				}
				
			});
		
		}
	    function saveStorage() {
	        // 如果勾选了复选框，则使用Local Storge保存数据
	        // 否则，用Session Storage保存数据
	        var checked = document.getElementById("loginCheckbox1").checked;
	        var storage = localStorage;
	        storage.setItem("user_name", document.getElementById('user_name').value);
	        storage.setItem("passwords", document.getElementById('passwords').value);
	    }
	    function rememberMe() {
	        var checked = document.getElementById("loginCheckbox1").checked;
	        var storage = localStorage;
	        if (checked) {
	            saveStorage();
	        } else {
	            storage.setItem("user_name", "");
	            storage.setItem("passwords", "");
	        }
	    }
	    // 忘记密码实现相关：
	    function pwRetrieve() {
	        testdata = {};
	        testdata.username = $('#pw_retrieve_user').val();
	        $.ajax({
	            type:"POST",
	            url:'/login/forgetpw',
	            dataType:"json",
	            data:testdata,
	            beforeSend:function(XHR) {
	                switchDiv();
	            },
	            error:function(request) {
	                alert("邮件发送失败，请稍后重试！");
	                switchDiv();
	            },
	            success:function(data) {
	                switchDiv();
	                switch(data.result) {
	                    case 0:
	                        if(confirm("找回密码的邮件已发送至："+data.content+"\n点击'确认'关闭此页")) {
	                            window.opener=null;
	                            window.open('','_self');
	                            window.close();
	                        }
	                        break;
	                    case 1:
	                        alert("该用户不存在！");
	                        break;
	                    case 2:
	                        alert("要找回密码用户的邮箱不合法，请联系维护人员！");
	                        break;
	                    case 3:
	                        alert("发送失败，请稍后重试！");
	                        break;
	                }
	            }
	        });
	    }
	    function switchDiv() {
	        $('#login-forgot').toggle("slow");
	        $('#waiting').toggle("slow");
	    }
	</script>
  	
  </body>
</html>
